package com.googlecode.lookie.core.log;

import java.util.HashSet;
import java.util.Set;

import com.googlecode.lookie.core.log.LogStoreListener.ChangeType;

public abstract class AbstractLogStore
    implements LogStore
{

    private Set<LogStoreListener> logStoreListeners = new HashSet<LogStoreListener>( 5 );

    protected void notifyChange( ChangeType type )
    {
        LogStoreListener[] listeners = null;
        synchronized ( logStoreListeners )
        {
            listeners = (LogStoreListener[]) logStoreListeners.toArray( new LogStoreListener[logStoreListeners.size()] );
        }
        for ( LogStoreListener listener : listeners )
        {
                notifyChange( listener, type );
        }
    }

    protected void notifyChange( LogStoreListener listener, ChangeType type )
    {
        listener.changed( this, type );
    }

}
